﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharedLib.WinFormMVCFramework.ExceptionHandling;
using System.Collections.Specialized;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;

namespace TracyGUI.ExceptionHandling
{
    [ConfigurationElementType(typeof(CustomHandlerData))]
    public class UIExceptionHandler : AbstractUIExceptionHandler, IExceptionHandler
    {
        public UIExceptionHandler(NameValueCollection ignore):base(ignore)
        {
        }
        protected override string DialogTitle
        {
            get { return "Application Error"; }
        }

        protected override string FormatMessage(string message, Guid handlingInstanceId)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("Error: ");
            sb.AppendLine("{0}");
            sb.AppendLine();
            sb.AppendLine("Error instance ID: {1}");
            sb.AppendLine("Please post on http://tracy.codeplex.com/workitem/list/basic with the id above and C:\\Users\\{Username}\\AppData\\Local\\Temp\\Tracy\\trace.log attached for help.");
            return String.Format(Tracy.TracyFacade.Instance.LanguageManager.GetText("ErrorMessage_UIExceptionHandler") ?? sb.ToString(), message, handlingInstanceId.ToString());
        }

        public override Exception HandleException(Exception exception, Guid handlingInstanceId)
        {
            if (exception is IgnorableException) return exception;
            return base.HandleException(exception, handlingInstanceId);
        }
    }
}
